package com.cnplan.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.cnplan.entity.*;
import com.cnplan.mapper.*;
import com.cnplan.service.GisService;
import com.cnplan.vo.QjsgcVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

@Service
public class GisSereviceImpl implements GisService {
    @Autowired
    private GisCenterlineMapper gisCenterlineMapper;

    @Autowired
    private GisFwMapper gisFwMapper;

    @Autowired
    private GisKxfmMapper gisKxfmMapper;

    @Autowired
    private GisKxfwMapper gisKxfwMapper;

    @Autowired
    private GisKxjfMapper gisKxjfMapper;

    @Autowired
    private GisKxsjMapper gisKxsjMapper;

    @Autowired
    private GisQjsgcMapper gisQjsgcMapper;

    @Autowired
    private GisRedlineMapper gisRedlineMapper;

    @Autowired
    private GisSpgcMapper gisSpgcMapper;

    @Autowired
    private GisZdMapper gisZdMapper;

    @Override
    public Object getGis(String x,String y,String name) {
        /*switch (name){
            //中心线
            case "centerline":
                obj = gisCenterlineMapper.getAllByGeom(x, y);
                break;
                //房屋
            case "fw":
                obj = gisFwMapper.getAllByGeom(x, y);
                break;
                //控详风貌
            case "kxfm":
                obj = gisKxfmMapper.getAllByGeom(x, y);
                break;
                //控详范围
            case "kxfw":
                obj = gisKxfwMapper.getAllByGeom(x, y);
                break;
                //控详街坊
            case "kxjf":
                obj = gisKxjfMapper.getAllByGeom(x, y);
                break;
                //控详数据
            case "kxsj":
                obj = gisKxsjMapper.getAllByGeom(x, y);
                break;
                //区批项目
            case "qjsgc":
                obj = gisQjsgcMapper.getAllByGeom(x, y);
                break;
                //道路红线
            case "redline":
                obj = gisRedlineMapper.getAllByGeom(x, y);
                break;
                //市批项目
            case "spgc":
                obj = gisSpgcMapper.getAllByGeom(x, y);
                break;
                //宗地
            case "zd":
                obj = gisZdMapper.getAllByGeom(x, y);
                break;
        }*/
        JSONArray jsonArray = new JSONArray();
        if(!StringUtils.isEmpty(name) && name.contains(",")){
            String[] names = name.split(",");
            for (String s : names) {
                List<Object> list = new ArrayList<>();
                Object obj = null;
                Object object = null;
                switch (s){
                    //中心线
                    case "centerline":
                        obj = gisCenterlineMapper.getAllByGeom(x, y);
                        object = "中心线";
                        list.add(obj);
                        list.add(object);
                        break;
                        //房屋
                    case "fw":
                        obj = gisFwMapper.getAllByGeom(x, y);
                        object = "房屋";
                        list.add(obj);
                        list.add(object);
                        break;
                        //控详风貌
                    case "kxfm":
                        obj = gisKxfmMapper.getAllByGeom(x, y);
                        object = "控详风貌";
                        list.add(obj);
                        list.add(object);
                        break;
                        //控详范围
                    case "kxfw":
                        obj = gisKxfwMapper.getAllByGeom(x, y);
                        object = "控详范围";
                        list.add(obj);
                        list.add(object);
                        break;
                        //控详街坊
                    case "kxjf":
                        obj = gisKxjfMapper.getAllByGeom(x, y);
                        object = "控详街坊";
                        list.add(obj);
                        list.add(object);
                        break;
                        //控详数据
                    case "kxsj":
                        obj = gisKxsjMapper.getAllByGeom(x, y);
                        object = "控详数据";
                        list.add(obj);
                        list.add(object);
                        break;
                        //区批项目
                    case "qjsgc":
                        obj = gisQjsgcMapper.getAllByGeom(x, y);
                        object = "区批项目";
                        list.add(obj);
                        list.add(object);
                        break;
                        //道路红线
                    case "redline":
                        obj = gisRedlineMapper.getAllByGeom(x, y);
                        object = "道路红线";
                        list.add(obj);
                        list.add(object);
                        break;
                        //市批项目
                    case "spgc":
                        obj = gisSpgcMapper.getAllByGeom(x, y);
                        object = "市批项目";
                        list.add(obj);
                        list.add(object);
                        break;
                        //宗地
                    case "zd":
                        obj = gisZdMapper.getAllByGeom(x, y);
                        object = "宗地";
                        list.add(obj);
                        list.add(object);
                        break;
                }
                    jsonArray.add(list);
            }
        }else if(!StringUtils.isEmpty(name)){
            List<Object> list = new ArrayList<>();
            Object obj = null;
            Object object = null;
            switch (name){
                //中心线
                case "centerline":
                    obj = gisCenterlineMapper.getAllByGeom(x, y);
                    object = "中心线";
                    list.add(obj);
                    list.add(object);
                    break;
                //房屋
                case "fw":
                    obj = gisFwMapper.getAllByGeom(x, y);
                    object = "房屋";
                    list.add(obj);
                    list.add(object);
                    break;
                //控详风貌
                case "kxfm":
                    obj = gisKxfmMapper.getAllByGeom(x, y);
                    object = "控详风貌";
                    list.add(obj);
                    list.add(object);
                    break;
                //控详范围
                case "kxfw":
                    obj = gisKxfwMapper.getAllByGeom(x, y);
                    object = "控详范围";
                    list.add(obj);
                    list.add(object);
                    break;
                //控详街坊
                case "kxjf":
                    obj = gisKxjfMapper.getAllByGeom(x, y);
                    object = "控详街坊";
                    list.add(obj);
                    list.add(object);
                    break;
                //控详数据
                case "kxsj":
                    obj = gisKxsjMapper.getAllByGeom(x, y);
                    object = "控详数据";
                    list.add(obj);
                    list.add(object);
                    break;
                //区批项目
                case "qjsgc":
                    obj = gisQjsgcMapper.getAllByGeom(x, y);
                    object = "区批项目";
                    list.add(obj);
                    list.add(object);
                    break;
                //道路红线
                case "redline":
                    obj = gisRedlineMapper.getAllByGeom(x, y);
                    object = "道路红线";
                    list.add(obj);
                    list.add(object);
                    break;
                //市批项目
                case "spgc":
                    obj = gisSpgcMapper.getAllByGeom(x, y);
                    object = "市批项目";
                    list.add(obj);
                    list.add(object);
                    break;
                //宗地
                case "zd":
                    obj = gisZdMapper.getAllByGeom(x, y);
                    object = "宗地";
                    list.add(obj);
                    list.add(object);
                    break;
            }
            jsonArray.add(list);
        }

        /*List<GisCenterlineEntity> allByGeom = gisCenterlineMapper.getAllByGeom(x, y);
        if(allByGeom.size()!=0){
            jsonArray.add(allByGeom);
        }
        List<GisFwEntity> allByGeom9 = gisFwMapper.getAllByGeom(x, y);
        if(allByGeom9.size()!=0){
            jsonArray.add(allByGeom9);
        }
        List<GisKxfmEntity> allByGeom8 = gisKxfmMapper.getAllByGeom(x, y);
        if(allByGeom8.size()!=0){
            jsonArray.add(allByGeom8);
        }
        List<GisKxfwEntity> allByGeom7 = gisKxfwMapper.getAllByGeom(x, y);
        if(allByGeom7.size()!=0){
            jsonArray.add(allByGeom7);
        }
        List<GisKxjfEntity> allByGeom6 = gisKxjfMapper.getAllByGeom(x, y);
        if(allByGeom6.size()!=0){
            jsonArray.add(allByGeom6);
        }
        List<GisKxsjEntity> allByGeom5 = gisKxsjMapper.getAllByGeom(x, y);
        if(allByGeom5.size()!=0){
            jsonArray.add(allByGeom5);
        }
        List<GisQjsgcEntity> allByGeom4 = gisQjsgcMapper.getAllByGeom(x, y);
        if(allByGeom4.size()!=0){
            jsonArray.add(allByGeom4);
        }
        List<GisRedlineEntity> allByGeom3 = gisRedlineMapper.getAllByGeom(x, y);
        if(allByGeom3.size()!=0){
            jsonArray.add(allByGeom3);
        }
        List<GisSpgcEntity> allByGeom2 = gisSpgcMapper.getAllByGeom(x, y);
        if(allByGeom2.size()!=0){
            jsonArray.add(allByGeom2);
        }
        List<GisZdEntity> allByGeom1 = gisZdMapper.getAllByGeom(x, y);
        if(allByGeom1.size()!=0){
            for (GisZdEntity gisZdEntity : allByGeom1) {
                jsonArray.add(gisZdEntity);
            }

        }*/
        return jsonArray;
    }

    @Override
    public List<QjsgcVo> getQjsgc(String gcxkz) {
        return gisQjsgcMapper.getQjsgc(gcxkz);
    }

    @Override
    public GisQjsgcEntity getQjsgcById(int id) {
        return gisQjsgcMapper.getQjsgcById(id);
    }


}
